package view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

import view.components.MenuBar;
import view.components.StatusBar;
import view.components.ToolBar;

/**
 * 
 * @author Igor Spremo, Milan Stojkov
 *
 */
@SuppressWarnings("serial")
public class MainFrame extends JFrame {

	private static MainFrame instance = null;

	private ToolBar toolbar;
	private StatusBar statusBar;
	private JLabel lblImage;

	private static final String IMAGE_LOCATION = "./data/logo.jpg";

	private MainFrame() {
		super();
		
		
	}

	public static MainFrame getInstance() {
		if (instance == null) {
			instance = new MainFrame();
			instance.init();
		}

		return instance;
	}

	public void init() {
		setTitle("Studio Spremo");
		
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		setSize((int) (d.getWidth() * 3 / 4), (int) (d.getHeight() * 3 / 4));
		
		setLocationRelativeTo(null);
		
		setExtendedState(MAXIMIZED_BOTH);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
		Image icon = Toolkit.getDefaultToolkit().getImage("./data/icon.png");
		setIconImage(icon);

		this.toolbar = new ToolBar();
		this.add(toolbar, BorderLayout.NORTH);

		this.statusBar = new StatusBar();
		this.add(statusBar, BorderLayout.SOUTH);

		this.lblImage = new JLabel(new ImageIcon(IMAGE_LOCATION));
		this.add(lblImage, BorderLayout.CENTER);

		this.setJMenuBar(new MenuBar());
		
		addWindowListener(new WindowAdapter() {

			@Override
			public void windowOpened(WindowEvent e) {
			}

			@Override
			public void windowClosing(WindowEvent e) {
			}

		});
	}

	public StatusBar getStatusBar() {
		return statusBar;
	}

	public void setStatusBar(StatusBar statusBar) {
		this.statusBar = statusBar;
	}
	
}